package us.quizgame;


import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.ImageIcon;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextPane;
import javax.swing.JTextArea;

import us.quizgame.database.Question;
import us.quizgame.quiz.QuizGame;


public class ReviewQuiz extends JFrame {

	private JPanel contentPane;
	private QuizGame retrieveQuestions;
	
	JTextArea textArea;
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					ReviewQuiz frame = new ReviewQuiz();
					frame.setVisible(true);
					frame.setLocationRelativeTo(null);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public ReviewQuiz() {
		setResizable(false);
		setBackground(Color.BLACK);
		setTitle("ReviewQuiz");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 550, 450);
		contentPane = new JPanel();
		contentPane.setBackground(Color.BLACK);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		textArea = new JTextArea();
				
		JScrollPane scrollPane = new JScrollPane(textArea);
		scrollPane.setBounds(10, 145, 514, 206);
		contentPane.add(scrollPane);
		
					
		JLabel reviewQuizLabel = new JLabel("Review Quiz");
		reviewQuizLabel.setFont(new Font("Tahoma", Font.PLAIN, 20));
		reviewQuizLabel.setHorizontalAlignment(SwingConstants.CENTER);
		reviewQuizLabel.setForeground(Color.WHITE);
		reviewQuizLabel.setBounds(35, 11, 120, 39);
		contentPane.add(reviewQuizLabel);
		
		JLabel lblNewLabel = new JLabel("New label");
		lblNewLabel.setIcon(new ImageIcon(Menu.class.getResource("/us/quizgame/images/av-20034.png")));
		lblNewLabel.setBounds(194, 6, 150, 99);
		contentPane.add(lblNewLabel);
		
		JButton btnMenu = new JButton("Menu");
		btnMenu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				close();
			}

		});
		btnMenu.setBounds(377, 378, 89, 23);
		contentPane.add(btnMenu);
	}
	
	public ReviewQuiz(QuizGame q)
	{
		this();
		this.retrieveQuestions = q;
		textArea.setText(showQuiz());
	}
	
	private void close() {
		Menu.main(null);
		retrieveQuestions.dispose();
		this.dispose();
	}

	private String showQuiz() {
		Question[] questions = retrieveQuestions.getQuestions();
		String result="";
		String answer = "";
		int i = 0;
		
		for (Question q : questions) {
			
			if (retrieveQuestions.userAnswers[i] == true){
				answer = "right";
			}else
				answer = "wrong";
		
			result += String.format("Question: %s \n\tRight Answer: %s  \n\tWrong Answer %s\n       You got this answer %s \n\n", q.getQuestion(), q.getCorrectAnswer(), q.getWrongAnswer(), answer);
			i++;
		}
		return result;
	}
}
